<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
include 'errors.php';
class Jobs extends Errors {
	public function __construct(){
		parent::__construct();
		$this->output->nocache();
		$this -> form_validation -> set_error_delimiters('<p class="help-block danger">', '</p>');
		$this->load->library('pagination');
		
	}
    public function index() {
       $this->error_404();
    }

    public function list_all_job() {
        $data['title'] = "List All Jobs";
        $data['locations'] = $this->model_globals->select_all('job_locations');
        $categories = $this->model_globals->select_all('job_categories')->result();
        $option = $this->get_job_category_options($categories);
        $data['categories'] = $option;
		
		$config = array();
        $config["base_url"] = base_url() . "jobs/list-all-job";
        $config["total_rows"] = $this->model_jobs->count_all_jobs(NULL);;
        $config["per_page"] = 25;
        $config["uri_segment"] = 3;
 
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["results"] = $this->model_jobs->list_all_jobs_ajax($config["per_page"], $page,NULL);
        $data["links"] = $this->pagination->create_links();
	
		$data['feature_jobs']=$this->model_jobs->fearture_job();
        $this->load->view(F_MASTER . "index", $data);
    }
    public function search_query() {
        $data['title'] = "Job Search";
        $data['locations'] = $this->model_globals->select_all('job_locations');
        $categories = $this->model_globals->select_all('job_categories')->result();
        $data['error']= false;
		
		$option = $this->get_job_category_options($categories);
        $data['categories'] = $option;
        if(isset($_GET['key_word']) && isset($_GET['category']) && isset($_GET['location'])){
            $keySearch = $_GET['key_word'];
            $categoryName = $_GET['category'];
            $locationName = str_replace('-',' ',$_GET['location']);
            
        }else{
            $keySearch = FALSE;
            $categoryName = FALSE;
            $locationName = FALSE;
        }
		$key_word_  = $_GET['key_word']==""?'?key_word=':'?key_word='.$_GET['key_word'];
		$category_  = $_GET['category']==""?'&category=':'&category='.$_GET['category'];
		$location_  = $_GET['location']==""?'&location=':'&location='.$_GET['location'];
		
    	$data['error'] = FALSE;
    	$config = array();
        $config["base_url"] = base_url() . "jobs/search-query/?search=true";
	
        $config["total_rows"] = $this->model_jobs->list_job_search($keySearch, $categoryName, $locationName);
        $config["per_page"] = 25;
        $config["uri_segment"] = 3;
 
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["results"] = $this->model_jobs->load_job_search($config["per_page"], $page, $keySearch, $categoryName, $locationName);
        $data["links"] = $this->pagination->create_links();
		
		$data['feature_jobs']=$this->model_jobs->fearture_job();
        $this->load->view(F_MASTER . "index", $data);
    }

    public function categories() {
        $data['title'] = "Job List By Categories";
        $job_category_key = $this->uri->segment(3);
        $job_category_id = $this->model_globals->select_string('job_categories', 'job_category_id', array('job_categories_keys' => $job_category_key));
        
		if($this->return_error_404($job_category_key,$job_category_id)){
			$this->error_404();
		}
        $data['job_sub_categories'] = $this->model_jobs->list_sub_category($job_category_id);

        $data['locations'] = $this->model_globals->select_all('job_locations');
		$config = array();
        $config["base_url"] = base_url() . "jobs/categories/".$job_category_key;
        $config["total_rows"] = $this->model_jobs->count_all_jobs($job_category_id);
        $config["per_page"] = 25;
        $config["uri_segment"] = 4;
 
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["results"] = $this->model_jobs->list_all_jobs_ajax($config["per_page"], $page, $job_category_id);
        $data["links"] = $this->pagination->create_links();
		$categories = $this->model_globals->select_all('job_categories')->result();
        $option = $this->get_job_category_options($categories);
        $data['categories'] = $option;
        $data['uri_category'] = $job_category_id;
		$data['feature_jobs']=$this->model_jobs->fearture_job();
        $this->load->view(F_MASTER . "index", $data);
    }
	/**
	 * This function need two paraemter, one is uri(3) and select string from database
	 * This function will return boolean
	 * $this->return_error_404($parameter_one, $paremeter_two)
	 */
	public function return_error_404($parameter_one, $paremeter_two){
		if($parameter_one=="" || $paremeter_two==NULL || $paremeter_two==""){
			return TRUE;
		}
		return FALSE;
	}

    public function locations() {
        $data['title'] = "Job List By Locations";
        $job_location_name = str_replace("-", " ", $this->uri->segment(3));
        $job_location_id = $this->model_globals->select_string('job_locations', 'job_location_id', array('job_locations.name' => $job_location_name));
		
		if($this->return_error_404($job_location_name,$job_location_id)){
			$this->error_404();
		}
		
		$config = array();
        $config["base_url"] = base_url() . "jobs/locations/".$this->uri->segment(3);
        $config["total_rows"] = $this->model_jobs->count_all_jobs_by_location($job_location_id);
        $config["per_page"] = 25;
        $config["uri_segment"] = 4;
 
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["results"] = $this->model_jobs->list_all_jobs_by_loction_ajax($config["per_page"], $page, $job_location_id);
        $data["links"] = $this->pagination->create_links();
		
        $data['locations'] = $this->model_globals->select_all('job_locations');
        $categories = $this->model_globals->select_all('job_categories')->result();
        $option = $this->get_job_category_options($categories);
        $data['categories'] = $option;
        $data['uri_loations'] = $job_location_id;
		$data['feature_jobs']=$this->model_jobs->fearture_job();
        $this->load->view(F_MASTER . "index", $data);
    }

    public function companies() {
        $data['title'] = "Job List By Companies";
        $job_company_key = $this->uri->segment(3);
        $job_company_id = $this->model_globals->select_string('companies', 'company_id', array('companies.company_keys' => $job_company_key));
        if($this->return_error_404($job_company_key,$job_company_id)){
			$this->error_404();
		}
        $data['company_name'] = $this->model_globals->select_string('companies', 'name', array('companies.company_keys' => $job_company_key));
        
        $config = array();
        $config["base_url"] = base_url() . "jobs/companies/".$this->uri->segment(3);
        $config["total_rows"] = $this->model_jobs->count_all_jobs_by_company($job_company_id);
        $config["per_page"] = 25;
        $config["uri_segment"] = 4;
		
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["results"] = $this->model_jobs->list_all_jobs_by_company_ajax($config["per_page"], $page,$job_company_id);
        $data["links"] = $this->pagination->create_links();
        
        $data['locations'] = $this->model_globals->select_all('job_locations');
        $categories = $this->model_globals->select_all('job_categories')->result();
        $option = $this->get_job_category_options($categories);
        $data['categories'] = $option;
		$data['feature_jobs']=$this->model_jobs->fearture_job();
        $this->load->view(F_MASTER . "index", $data);
    }
    
    public function sub_category(){
        $data['title'] = "Job List By Sub Category";
        $job_sub_category_key = $this->uri->segment(3);
        $job_sub_category_id = $this->model_globals->select_string('job_sub_categories', 'using_job_category_id', array('job_sub_categories_keys' => $job_sub_category_key));
        if($this->return_error_404($job_sub_category_key,$job_sub_category_id)){
			$this->error_404();
		}
        $data['job_sub_categories'] = $this->model_jobs->list_sub_category_($job_sub_category_id);
		
        $job_using_categoryId = $this->model_globals->select_string('job_sub_categories', 'job_sub_category_id', array('job_sub_categories_keys' => $job_sub_category_key));
        $data['category_name'] = $this->model_globals->select_string('job_categories', 'name', array('job_category_id' => $job_using_categoryId));
        
        $data['locations'] = $this->model_globals->select_all('job_locations');
		
		$config = array();
        $config["base_url"] = base_url() . "jobs/sub-category/".$this->uri->segment(3);
        $config["total_rows"] = $this->model_jobs->count_all_jobs_by_sub($job_using_categoryId);
        $config["per_page"] = 25;
        $config["uri_segment"] = 4;
		
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["results"] = $this->model_jobs->list_all_jobs_ajax_($config["per_page"], $page, $job_using_categoryId);
        $data["links"] = $this->pagination->create_links();
        
        $this->model_jobs->count_all_jobs_by_sub($job_using_categoryId);
        $categories = $this->model_globals->select_all('job_categories')->result();
        $option = $this->get_job_category_options($categories);
        $data['categories'] = $option;
        $data['uri_sub_category'] = $job_using_categoryId;
		$data['feature_jobs']=$this->model_jobs->fearture_job();
        $this->load->view(F_MASTER . "index", $data);
    }
 
    /*Send email function */
    public function send_email_to_friend() {
       
        $email_to = $_POST['email'];
        $username = $_POST['username'];
		$job_key= $_POST['job_key'];
		$link = base_url() . "jobs/detail/" . $job_key;
		$job_title = $this->model_globals->select_string('job_ads','title',array('job_ads.job_keys'=>$job_key));

       
        if ($this->is_send_job_offer_to_friend($email_to,$username,$link,$job_title)) {
			$this -> session -> set_flashdata('success' , 'Email has been sent.');
			redirect(base_url() . "jobs/detail/" . $job_key);
        } else {
			$this -> session -> set_flashdata('warning' , 'Email has not been sent.');
			redirect(base_url() . "jobs/detail/" . $job_key);
        }
    }
    
    private function is_send_job_offer_to_friend($email_to,$username,$link,$job_title){
    	$this->load->library('email');
		$this->email->set_mailtype("html");
		$message = "
			<p> Hi!,We are jobpending.com, your friend {$username} would like to send you a good annoucement about job offer which has title is <b>{$job_title}</b> , so
			 you could visit this <a href='{$link}'>{$link}</a> to see job 
			detail or press <a href='".base_url()."'>jobpending.com</a> to visit all jobs.
			
			<p>If you have any prblems or quetions, Please reply to current email.</p>
			
			<p>Best regards,</p>
			<p>Jobpending team</p>
			<p>================================================</p>
			<p>
				Email: info@jobpending.com<br />
				Tel: 015 59 17 37 / 069 90 91 69<br />
				Address: Nº 13, Street 420, Songkat Boeng Trabek,Khan Chamkar Morn, Phnom   Penh, Cambodia. <br />
				Facebook: <a href='https://www.facebook.com/pages/Jobpending/267500723459814'>https://www.facebook.com/pages/Jobpending/267500723459814</a>
			</p>";
		$this->email->from('info@jobpending.com', 'info@jobpending.com');
		$this->email->to($email_to); 
		$this->email->cc('jobpending.info@gmail.com');  
		
		$this->email->subject('Job announcement : '.$job_title);
		$this->email->message($message);	
		
		if($this->email->send()){
			return TRUE;
		}else{
			return FALSE;
		}
    }
    
    /*This function us to validate input field, mostly us for validate string field. */
    public function validate_Name($name) {
        if (!preg_match("/^[a-zA-Z ]*$/", $name)) {
            return "Only letters and white space allowed";
        }
        return false;
    }
    /*List specific job detail , eg. where job Id=5*/
    public function detail() {
        $this->load->library('math_question');
        $this->load->helper('form');
        
        $questionOne = $this->math_question->questionOne();
        $questionTwo = $this->math_question->questionTwo();

        $data['q1'] = $questionOne;
        $data['q2'] = $questionTwo;
        $data['math_questions'] = "What is {$questionOne} + {$questionTwo}?";
		$job_key = $this->uri->segment(3);
		$job_title=$this->model_globals->select_string('job_ads','title',array('job_keys'=>$job_key));
        /*Facebook share */
    	
        $data['locations'] = $this->model_globals->select_all('job_locations');
        $categories = $this->model_globals->select_all('job_categories')->result();
        $option = $this->get_job_category_options($categories);
        
        $data['categories'] = $option;
        
        $data['job_details'] = $this->model_jobs->list_job_detail($job_key);
		
		foreach($data['job_details']->result() as $row){
    		$job_title   = $row->job_title;
            $description = $row->job_description;
            $company_logo = $row->company_logo;
            
            $company_name = $row->company_name;
        }
        if($company_logo==NULL || $company_logo ==""){
            $image_path = base_url().F_IMG.'jobpending.png';
        }else{
            $image_path = base_url().F_IMG.'employer_logo/'.$company_logo;
        }
        
        
        $data['title'] = "Job announcement from ".$company_name." : ".$job_title;
		
  		$data['open_graph'] = '<!-- Facebook Metatag -->
		<meta property="article:publisher" content="https://www.facebook.com/pages/Jobpending/267500723459814" />
		<meta property="og:image" content="'.$image_path.'" />
		<meta property="og:title" content="Job announcement from '.$company_name.' ( '.$job_title.' )" />
		<meta property="og:url" content="http://demo.jobpending.com/jobs/detail/'.$job_key.'" />
		<meta property="og:description" content="'.word_limiter($description, 25).'" />
		<meta property="og:site_name" content="demo.jobpending.com" />';
		
        if($data['job_details']->result()==NULL){
            $this->error_404();
        }
         /*Report user views*/
        if($this -> is_seekerLogin()){
            $seekerEmail = $this->model_globals->select_string('job_seekers','email',array('job_seeker_id'=>$this -> session -> userdata('jobseeker_active_access')));
            $jobId = $this->model_globals->select_string('job_ads', 'job_ads_id', array('job_keys' => $job_key));
            $data_statistic = array(
            'using_job_ads_id'=>$jobId,
            'user_agent' => $_SERVER['HTTP_USER_AGENT'] ,
            'job_seeker_mail'=>$seekerEmail,
            'date_view' => date('Y-m-d'),
            'status'=>TRUE,
            'created_date'=>NULL
            );
            $this->model_globals->insert('job_statistics', $data_statistic); 
        }else{
            $jobId = $this->model_globals->select_string('job_ads', 'job_ads_id', array('job_keys' => $job_key));
            $data_statistic = array(
            'using_job_ads_id'=>$jobId,
            'user_agent' => $_SERVER['HTTP_USER_AGENT'],
            'date_view' => date('Y-m-d'),
            'status'=>TRUE,
            'created_date'=>NULL
            );
           
            $this->model_globals->insert('job_statistics', $data_statistic); 
        }
		$data['feature_jobs']=$this->model_jobs->fearture_job();
        $this->load->view(F_MASTER . "index", $data);
        
    }
    /*This function use to check user login or not*/
    /*Return Boolean*/
    public function is_seekerLogin(){
        return $this -> session -> userdata('jobseeker_active_access')!=FALSE;
    }
	
    /*This function us to validate random number*/
    function math_question() {
        $user_answer = $this->input->post('math_question');
        $questionOne = $this->session->flashdata('questionOne');
        $questionTwo = $this->session->flashdata('questionTwo');

        $correct_answer = $questionOne + $questionTwo;

        if ($user_answer != $correct_answer) {
            $this->form_validation->set_message('math_question', 'Your answer to the math question was incorrect');
            return FALSE;
        } else {
            return TRUE;
        }
    }

    /*Load result with jax request*/
    /*This function us in all views function*/
    public function forearch_result($results){
        if ($results) {
            if ($results != null && $results->num_rows > 0) {
                foreach ($results->result() as $row) {
                    //$jobId = $row->job_ads_id;
                    $description = character_limiter($row->job_description, 170);
					
                    ?>
                    
                    <div class="list-job-white">
                    <?php
                    echo "<a class='job-load-title' href='" . base_url() . "jobs/detail/" . $row->job_keys . "'>
                    <span>" . $row->job_title . "</span></a>";
                    $exp_date = date("Y-m-d",strtotime($row->date_available)); 
                    $todays_date = date("Y-m-d"); 
                    $today = strtotime($todays_date);
                    $expiration_date = strtotime($exp_date);
                    if ($today > $expiration_date){
                    	echo "&nbsp;<span class='label label-danger'> Expired </span>";
                    }else if($today == $expiration_date){
                    	echo "&nbsp;<span class='label label-info'> Nearly Expire </span>";
                    }else if($this->is_feature_job($row->is_featured_job,$row->featured_job_status)){
						echo "&nbsp;<span class='label label-warning'> Ads</span>";
                    }
					
                   
                    echo "<span class='pull-right job-expire'> Avaliable on : " .  date("d-M-Y", strtotime($row->date_available)) . "</span>";
                    echo "<p> " . $row->company_name . " - " . $row->location_name; 
					if(strtotime($row->job_create_date) > strtotime("-1 day")){
						echo " - <b class='post-today'> Posted today</b>";
					}
					echo "</p>";
                    echo "<a class='btn-read-more pull-right' href='" . base_url() . "jobs/detail/" . $row->job_keys . "'>View Detail<i class='fa fa-fw fa-angle-double-right'></i></a>";

                    echo "<p>" . strip_tags($description) . "</p>";
                    echo "</div>";
                }
            } else {
                echo " <div id='contain-no-result'>
                          <h3 id='no-result'>No resutl!</h3>
                       </div>";
            }
        }
    }
	public function is_feature_job($is_feature,$feature_status){
		if($is_feature=='YES' && $feature_status == 1){
			return true;
		}else{
			return false;
		}
	}
	
	public function apply_job_online(){
		$job_keys=$this->uri->segment(3);
		//check login before apply job
		if (!$this -> session -> userdata('jobseeker_active_access')) {
			$this -> session -> set_flashdata('warning', 'You have to login with your account before you can apply job online!.');
			$this->session->set_userdata('request_login_before_apply_job',$job_keys);
			redirect("jobseekers/login");
		}
		//clear session request before apply job
		if($this->session->userdata('request_login_before_apply_job')){
			$this->session->unset_userdata('request_login_before_apply_job');
		}
		
		$job_seeker_id=$this -> session -> userdata('jobseeker_active_access');
		$job_id=$this->model_globals->select_string('job_ads','job_ads_id',array('job_keys'=>$job_keys));
		
		if($job_id<=0 || $job_id=""){
			$this->error_404();
		}else{
			//check exist cv
		$is_exist_cv_upload=$this->model_globals->check_data_exist('seeker_documents',array('using_seeker_id'=>$job_seeker_id,'is_resume'=>'YES'));
		$is_exist_cv_editor=$this->model_globals->check_data_exist('resume_text_editors',array('using_job_seeker_id'=>$job_seeker_id));
		$is_exist_cv_creator=$this->model_globals->check_data_exist('resume',array('using_job_seeker_id'=>$job_seeker_id));
		
		if(!$is_exist_cv_upload && !$is_exist_cv_editor && !$is_exist_cv_creator){
			$this -> session -> set_flashdata('warning', 'You have to  <a href="'.base_url().'jobseekers/documents" target="_blink">upload your own cv</a> or  <a href="'.base_url().'jobseekers/resume" target="_blink">create your online cv</a> in our website before you can apply job online!.');
			redirect('jobs/detail/'.$job_keys);
		}else{
			// check if apply job already
			$is_already_apply=$this->model_globals->check_data_exist('job_seeker_applied_jobs',array('using_job_ads_id'=>$job_id),array('using_job_seeker_id'=>$job_seeker_id));
			if($is_already_apply){
				$this -> session -> set_flashdata('info', 'You have been applied to this job already.If you have any concern with it.Please contact us...');
				redirect('jobs/detail/'.$job_keys);
			}
			$data=array(
				'using_job_ads_id'=>$job_id,
				'using_job_seeker_id'=>$job_seeker_id,
				'apply_status'=>'Pending',
				'apply_date'=>date('y-m-d'),
				'status'=>1,
				'created_date'=>null
			);	
			$is_inserted=$this->model_globals->insert('job_seeker_applied_jobs',$data);
			//checking if notification and  send mail
			$job_info=$this->model_globals->select_where('job_ads',array('job_ads_id'=>$job_id));
			if($job_info->row()->notification==1){
				$employer_job_id=$job_info->row()->using_employer_id;
				$job_title=$job_info->row()->title;
				
				$data['employer_info'] = $this -> model_globals -> select_join_get_only_fields('employers', $arr_fields = array('username', 'email', 'name', 'logo'), array('companies' => array('employer_id' => 'using_employer_id')), $join_type = 'INNER', $arr_where = array('employer_id' => $employer_job_id), $limit = 1, $sort = NULL);
				$employer_name=$data['employer_info']->row()->username;
				$employer_email=$data['employer_info']->row()->email;
				$company_name=$data['employer_info']->row()->name;
				
				$this->send_job_notification_to_employer_job($job_title,$employer_name,$employer_email,$company_name);	
			}
			
			
			if($is_inserted){
				$this -> session -> set_flashdata('success', 'You have been applied job to this company successfully !.');
				redirect('jobs/detail/'.$job_keys);
			}else{
				$this -> session -> set_flashdata('error', 'You have been applied job to this company fail !');
				redirect('jobs/detail/'.$job_keys);
			}
		}
		}
		
		
	}

	//send mail//
	public function send_job_notification_to_employer_job($job_title,$employer_name,$employer_email,$company_name){
		$this->load->library('email');
		$this->email->set_mailtype("html");
		$message="Dear $employer_name ,<br />
						<p>We would like to confirm you that recently there is a jobseeker has been applied job to $company_name as the position $job_title that you have post on jobpending.com website.</p>
						
						
						<p>So, Please login to your account in order to see detail information about it.</p>
						
						</p>if you have any problems or questions, Please reply to this email.</p>
						
						</p>Best regard,</p>
						</p>Jobpending team</p>
						<p>================================================</p>
						<p>
							Email: info@jobpending.com<br />
							Tel: 015 59 17 37 / 069 90 91 69<br />
							Address: Nº 13, Street 420, Songkat Boeng Trabek,Khan Chamkar Morn, Phnom   Penh, Cambodia. <br />
							Facebook: <a href='https://www.facebook.com/pages/Jobpending/267500723459814'>https://www.facebook.com/pages/Jobpending/267500723459814</a>
						</p>";
		$this->email->from('info@jobpending.com', 'info@jobpending.com');
		$this->email->to($employer_email); 
		$this->email->cc('jobpending.info@gmail.com'); 
		//$this->email->bcc('them@their-example.com'); 
		
		$this->email->subject('Apply job as position '.$job_title.' at '.$company_name);
		$this->email->message($message);	
		
		if($this->email->send()){
			return TRUE;
		}else{
			echo $this->email->print_debugger();
			exit;
			return FALSE;
		}
	}

    /*Share job to facebook*/
    public function facebook_share(){
        $job_key = $this->uri->segment(4);
        $data['job_details'] = $this->model_jobs->list_job_detail($job_key);
        $image_path = base_url().F_IMG.'jobpending.png';
        foreach($data['job_details']->result() as $job_info){
            $description = $job_info->description;
        }
  		$data['open_graph'] = '<meta property="og:site_name" content="jobpending.com" />
  		<meta property="og:title" content="Description of the image:" />
  		<meta property="og:type" content="jobpending" />
    
		<meta property="og:url" content="'.base_url().'jobs/detail/'.$job_key.'" />
		<meta property="og:image" content="'.$image_path.'" />
		<meta property="og:locale" content="en_US" />
		<meta property="og:description" content="'.$description.'" />';
    }
	
	/* add to favorites*/
	public function add_to_favorite(){
		$job_keys=$this->uri->segment(3);
		//check login before apply job
		if (!$this -> session -> userdata('jobseeker_active_access')) {
			$this -> session -> set_flashdata('warning', 'You have to <a href="'.base_url().'jobseekers/login" target="_blank">login</a> with your account before you can add this job to your favorite or click here to <a href="'.base_url().'jobseekers/register" target="_blank">create your account</a>!.');
			redirect("jobs/detail/".$job_keys);
		}
		
		$job_seeker_id=$this -> session -> userdata('jobseeker_active_access');
		$job_id=$this->model_globals->select_string('job_ads','job_ads_id',array('job_keys'=>$job_keys));
		
		if($job_id==null || $job_id==""){
			$this->error_404();
		}else{
			//check exist cv
		$is_already_add=$this->model_globals->check_data_exist('job_favorites',array('using_job_seeker_id'=>$job_seeker_id,'using_job_ads_id'=>$job_id));
		if($is_already_add){
			$this -> session -> set_flashdata('warning', 'You have been added this job to your favorite already.Thank you.');
			redirect("jobs/detail/".$job_keys);
		}else{
			
			$data=array('using_job_seeker_id'=>$job_seeker_id,'using_job_ads_id'=>$job_id,'status'=>1,'created_date'=>null);
			$is_inserted=$this->model_globals->insert('job_favorites',$data);
			if($is_inserted){
				$this -> session -> set_flashdata('success', 'You have been added this job to your favorite successfully !.');
				redirect('jobs/detail/'.$job_keys);
			}else{
				$this -> session -> set_flashdata('error', 'You have been added this job to your favorie fail.Please try again !');
				redirect('jobs/detail/'.$job_keys);
			}
		}
		}
		
	}
	public function get_job_category_options($categories){
		$option='';
		foreach ($categories as $category) {
			$category_id = $category -> job_category_id;
			$name = $category -> name;
			//$option .= '<optgroup label="' . $name . '">';
			$option .= '<option value="' . $category_id . '-0 "style="color:#3C8DBC;">' . $name . '</option>';
			$sub_categories = $this -> model_globals -> select_where('job_sub_categories', array('using_job_category_id' => $category_id)) -> result();
			foreach ($sub_categories as $sub_category) {
				$sub_category_id = $sub_category -> job_sub_category_id;
				$sub_name = $sub_category -> name;
				$option .= '<option value="' . $category_id . '-' . $sub_category_id . '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $sub_name . '</option>';
			}
			//$option .= '</optgroup>';
		}
		return $option;
		
	}
}
